package com.springboot.shanhexin.dao;

import com.springboot.shanhexin.entity.tourist;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Component;

import java.util.List;

@Component(value = "touristDao")
public interface touristDao {

    //我的路线：tourist_route

    /**
     * 显示总数量
     * @return
     */
    @Select("select count(*) from tourist_route")
    int getCount();

    /**
     * 全部分页显示
     * @return
     */
    @Select("select a.*,b.name as username from tourist_route a,userinfo b where a.uid=b.openid limit #{pos},#{size}")
    List<tourist> findByPage(@Param("pos")int pos, @Param("size")int size);

    /**
     * 显示搜索的总数量
     * @return
     */
    @Select("select count(*) from tourist_route a,userinfo b where a.uid=b.openid" +
            " and ${key} like concat(concat('%',#{name}),'%')")
    int getsearchCount(@Param("key")String key,@Param("name")String name);

    /**
     * 搜索并分页显示
     * @return
     */
    @Select("select a.*,b.name as username from tourist_route a,userinfo b where a.uid=b.openid" +
            " and ${key} like concat(concat('%',#{name}),'%') limit #{pos},#{size}")
    List<tourist> findsearchByPage(@Param("key")String key, @Param("name")String name, @Param("pos")int pos, @Param("size")int size);

    /**
     * 新增
     */
    @Insert("insert into tourist_route(uid,title,my_rode) values(#{uid},#{title},#{my_rode})")
    void add(tourist tourist);

    /**
     * 删除
     */
    @Delete("delete from tourist_route where id=#{id}")
    void delete(@Param("id")int id);

    /**
     * 修改(先找到并显示，再修改)
     */
    @Select("select a.*,b.name as username from tourist_route a,userinfo b where a.uid=b.openid and a.id=#{id}")
    List<tourist> getUserone(@Param("id")int id);

    @Update("update tourist_route set uid=#{uid},title=#{title},my_rode=#{my_rode} where id=#{id}")
    void update(tourist tourist);

}
